package com.example.baseadapter;

import java.util.ArrayList;

import android.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

class Adapter extends BaseAdapter { /*
	 * titles and detail are defined in
	 * strings.xml String[] titles; String[]
	 * detail; //this getCount() method return
	 * number of elements in the array but we
	 * have two or more array which //array
	 * element it will return. So we make an
	 * object in which each array object will
	 * exist. So we maintain a arraylist of
	 * object type of single row which contain
	 * our all these array in a object.
	 */
DatabaseHelper db;
ArrayList<Case> list;
Context context;

// initializing arraylist inside the constuctor
// We need an access to the resources so that we can call string_array
// so we pass context in the constuctor to get the resources.
Adapter(Context c) {
context = c;
list = new ArrayList<Case>();
db=new DatabaseHelper(context);
list=(ArrayList<Case>) db.getAllCases();
// now we have to put values of array in the object and in the array
// list.
// for 10 string values
// pass the constructor to the SingleRow class that will return the
// object.


}

@Override
public int getCount() {
// in this we have to pass the number of items in the list which is our
// number of items
// in the array list so list.size() will return the size of the list.
return list.size();
}

@Override
public Object getItem(int i) {
// this method will return the object of a single row in which i is the
// value of the row.
return list.get(i);
}

// this method is used in databases but we are not using any databases.
// we are using array so i will be the index of the row.
@Override
public long getItemId(int i) {

return i;
}

// this is the method to set the view for a single row which is inside the
// single_row.xml
// this will return view of the each row,for view of zeroth row i=0,first
// row i=1 and so on.
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
// first is get the root view which is Relativelayout in this case
// inside the single_row.xml
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// we get the view of the single row of list view in the object row.
View row = inflater.inflate(0x7f03001f, viewGroup, false);
TextView title = (TextView) row.findViewById(0x7f050062);
TextView vs = (TextView) row.findViewById(0x7f050063);
TextView detail = (TextView) row.findViewById(0x7f050064);



// now get the values of each row from the object and i variable and set
// to the view,

Case temp = list.get(i);
title.setText(temp.plaintiff);
detail.setText(temp.respondent);
vs.setText("VS");


// now return the view of the rows.
return row;
}


}
